// src/utils/markdown.js
import MarkdownIt from 'markdown-it';
import hljs from 'highlight.js';
import markdownItHighlightjs from 'markdown-it-highlightjs'
import 'highlight.js/styles/github-dark-dimmed.min.css'

const md = new MarkdownIt({
    html: true,        // 启用HTML标签解析
    linkify: true,     // 自动识别URL并转换为链接
    typographer: true, // 改善排版
    highlight: function (str, lang) {
        if (lang && hljs.getLanguage(lang)) {
            try {
                return (
                    '<pre class="hljs"><code>' +
                    hljs.highlight(lang, str, true).value +
                    '</code></pre>'
                );
            } catch (__) {
            }
        }
        return (
            '<pre class="hljs"><code>' +
            md.utils.escapeHtml(str) +
            '</code></pre>'
        );
    }
}).use( markdownItHighlightjs );


export default md;
